# from apps.libs.ansible.runner import ANSRunner
# if __name__ == '__main__':
#     resource=[{"hostname": "10.91.74.200", "port": "22", "username": "root", "password": "nomore532"}]
    
#     # AnsiableAPI(inventory=resource)
#     rbt = ANSRunner(resource)
#     rbt.run_model(host_list=["10.91.74.200"],module_name='shell',module_args="ls")
#     data = rbt.get_model_result()
#     print(data)


import paramiko
import os,re



def ssh_tool(ip,command,username,password):
    try:
        ssh = paramiko.SSHClient()
        key = paramiko.AutoAddPolicy()
        ssh.set_missing_host_key_policy(key)
        ssh.connect(ip,22,username,password,timeout=5)
        stdin,stdout,stderr=ssh.exec_command(command)
        
        result_data=[]
        for i in stdout.readlines():
            if 'VTL Name' in i or 'Replication' in i:
                # key = i.strip().split('=')[0].strip()
                value=i.strip().split('=')[1].strip()
                result_data.append(value)
            
        return {ip:result_data}
    except Exception as e:
         print(e)

def main():
    key_list=['VTLName','ReplicationStarted','ReplicationFinished','ReplicationStatus']

    all_data=[]
    for ip in ['10.91.74.185','10.91.74.224','10.91.74.225','10.91.74.226']:
        data=ssh_tool(ip,"syscli  --list  repvtl","cliadmin","cliadmin")
        list_data=[]
        for i in range(0,len(data[ip]),4):
            format_data=dict(zip(key_list,data[ip][i:i+4]))
            list_data.append(format_data)
        all_data.append({ip:list_data})
    return all_data()    


if __name__ == '__main__':
    main()

                   

                    

                    
                    
            


        
        